package com.ieasy.module.oa.project.web.action;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ieasy.basic.model.DataGrid;
import com.ieasy.basic.model.Msg;
import com.ieasy.basic.util.cons.Const;
import com.ieasy.module.common.web.action.BaseController;
import com.ieasy.module.oa.project.service.IForecastService;
import com.ieasy.module.oa.project.web.form.ForecastForm;

@Controller
@RequestMapping("/admin/oa/forecast")
public class ForecastAction extends BaseController {
	
	@Autowired
	private IForecastService forecastService ;
	
	/**
	 * 部长输入主页
	 * @return
	 */
	@RequestMapping("/forecast_main_UI.do")
	public String forecast_main_UI() {
		return Const.PROJECT + "forecast_main_UI" ;
	}
	
	/**
	 * 所有部门项目列表
	 * @return
	 */
	@RequestMapping("/forecast_all_UI.do")
	public String forecast_all_UI() {
		return Const.PROJECT + "forecast_all_UI" ;
	}
	
	/**
	 * 部长输入表单
	 * @return
	 */
	@RequestMapping("/forecast_form_UI.do")
	public String forecast_form(ForecastForm form, Model model) {
		if(null != form.getId() && !"".equals(form.getId())) {
			model.addAttribute("id", form.getId()) ;
		}
		if(null != form.getYear() && !"".equals(form.getYear())) {
			model.addAttribute("year", form.getYear()) ;
		}
		return Const.PROJECT + "forecast_form_UI" ;
	}
	
	@RequestMapping("/add.do")
	public @ResponseBody Msg add(ForecastForm form) throws Exception {
		return this.forecastService.add(form) ;
	}
	
	
	@RequestMapping("/delete.do")
	public @ResponseBody Msg delete(ForecastForm form) throws Exception {
		return this.forecastService.delete(form) ;
	}
	
	@RequestMapping("/update.do")
	public @ResponseBody Msg update(ForecastForm form) throws Exception {
		return this.forecastService.update(form) ;
	}
	
	@RequestMapping("/get.do")
	public @ResponseBody ForecastForm get(ForecastForm form) throws Exception {
		return this.forecastService.get(form) ;
	}
	
	@RequestMapping("/getByYear.do")
	public @ResponseBody ForecastForm getByYear(ForecastForm form) throws Exception {
		return this.forecastService.getByYear(form) ;
	}
	
	@RequestMapping("/datagrid.do")
	public @ResponseBody DataGrid datagrid(ForecastForm form) {
		DataGrid datagrid= null;
		try {
			datagrid = this.forecastService.datagrid(form) ;
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return datagrid ;
	}
	
	@RequestMapping("/getDeptOwnerList.do")
	public @ResponseBody DataGrid getDeptOwnerList(ForecastForm form) {
		DataGrid datagrid= null;
		try {
			datagrid = this.forecastService.getDeptOwnerList(form) ;
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return datagrid ;
	}
	
	@RequestMapping("/getAllDeptOwnerList.do")
	public @ResponseBody DataGrid getAllDeptOwnerList(ForecastForm form) {
		DataGrid datagrid= null;
		try {
			datagrid = this.forecastService.getAllDeptOwnerList(form) ;
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return datagrid ;
	}
	
	@RequestMapping("/doNotNeedAuth_getCustCategory.do")
	public @ResponseBody List<ForecastForm> doNotNeedAuth_getCustCategory(ForecastForm form) {
		return this.forecastService.getCustCategory() ;
	}
	
	
	/**
	 * １．顧客別の毎月リソース予定（上限）
	 * @return
	 */
	@RequestMapping("/forecast_total_up_UI.do")
	public String forecast_total_up_UI() {
		return Const.PROJECT + "forecast_total_up_UI" ;
	}
	@RequestMapping("/doNotNeedAuth_forecast_total_up.do")
	public @ResponseBody List<ForecastForm> forecast_total_up(ForecastForm form) {
		return this.forecastService.forecast_total_up(form) ;
	}
	
	/**
	 * ２．顧客別の毎月リソース予定（下限）
	 * @return
	 */
	@RequestMapping("/forecast_total_down_UI.do")
	public String forecast_total_down_UI() {
		return Const.PROJECT + "forecast_total_down_UI" ;
	}
	@RequestMapping("/doNotNeedAuth_forecast_total_down.do")
	public @ResponseBody List<ForecastForm> forecast_total_down(ForecastForm form) {
		return this.forecastService.forecast_total_down(form) ;
	}
	
	/**
	 * 汇总
	 * @return
	 */
	@RequestMapping("/forecast_report_UI.do")
	public String forecast_report_UI() {
		return Const.PROJECT + "forecast_report_UI" ;
	}
	@RequestMapping("/doNotNeedAuth_forecast_report.do")
	public @ResponseBody List<Map<String, Object>> doNotNeedAuth_forecast_report(ForecastForm form) {
		return this.forecastService.forecast_report(form) ;
	}
}
